﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _2023._5._8超市收银系统
{
    class StoreHouse
    {
        List<List<Goods>> House = new List<List<Goods>>();
        /// <summary>
        /// 存货
        /// </summary>
        /// <param name="p"></param>
        /// <param name="count"></param>
        public void Instorage(string name,int count)
        {
            Goods p = new Goods();
            switch(name)
            {
                case "苹果":
                     p = new Apple();
                break;
                case "华为手机":
                     p = new HuaiweiMbilePhone();
                    break;
            }
            Goods[] temp = new Goods[count];
            for (int i = 0; i < count; i++)
            {
                temp[i] = p;
            }
            int flag = 0;
            for(int i=0;i<House.Count;i++)
            {
                if((House[i][0].GetType()).Name==(p.GetType()).Name)
                {
                    for (int j = 0; j < count; j++)
                    {
                        House[i].Add(temp[j]);
                    }
                    flag = 1;
                    break;

                }
            }
            if(flag==0)
            {
                House.Add(new List<Goods>());
                for (int j = 0; j < count; j++)
                {
                    House[House.Count-1].Add(temp[j]);
                }
            }
            
        }
      
        /// <summary>
        /// 取货
        /// </summary>
        /// <param name="name">类名</param>
        /// <param name="count">数量</param>
        /// <returns></returns>
        public Goods[] OutStorage(string name,int count)
        {
            int flag = 0;
            Goods[] temp = new Goods[count];
            for (int i = 0; i < House.Count; i++)
            {
                if (House[i][0].Nmae ==name)
                {
                    for(int j=0;j<count;j++)
                    {
                        temp[j] = House[i][0];
                        House[i].RemoveAt(0);
                    }
                    flag = 1;
                    
                }
            }
            if (flag == 0)
            {
                Console.WriteLine("货物不存在");
                return null;
            }
            return temp;

        }

        /// <summary>
        /// 打印仓库信息
        /// </summary>
        public void Print()
        {
            foreach (var item in House)
            {
                Console.WriteLine("我们仓库有" + item[0].Nmae + "，数量为" + item.Count + ",价格为" + item[0].Price);
            }
       
        }
    }
}
